home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / OS / FWGraphx / Include / FWRect.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  3.4 KB  |  107 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWRect.h
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1993, 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWRECT_H
  13. #define FWRECT_H
  14.  
  15. #ifndef FWPOINT_H
  16. #include "FWPoint.h"
  17. #endif
  18.     
  19. //==============================================================================
  20. //    •• Typedefs
  21. //==============================================================================
  22.  
  23. typedef unsigned short FW_PointSelector;
  24.  
  25. const FW_PointSelector FW_kTopLeft = 0;
  26. const FW_PointSelector FW_kBotRight = 1;
  27.  
  28. //==============================================================================
  29. //    •• struct FW_CRect
  30. //==============================================================================
  31.  
  32. struct FW_CRect : public XMPRect
  33. {
  34.  
  35. public:
  36.     // ----- Constructors -----    
  37.     FW_CRect() {left = right = top = bottom = 0;}
  38.     FW_CRect(XMPCoordinate l, XMPCoordinate t, XMPCoordinate r, XMPCoordinate b)
  39.             {left=l; top=t; right=r; bottom=b; }
  40.     FW_CRect(const FW_CPoint& topLeft, const FW_CPoint& botRight);
  41.     FW_CRect(const FW_CPoint &topLeft, XMPCoordinate width, XMPCoordinate height);
  42.     FW_CRect(const FW_SPlatformRect& plfmRect);
  43.     
  44.     // ----- Assignement -----    
  45.     FW_CRect& operator=(const XMPRect& xmpRect);
  46.     FW_CRect& operator=(const FW_SPlatformRect& plfmRect);
  47.     
  48.     // ----- Conversion -----
  49.     void    AsPlatformRect(FW_SPlatformRect& plfmRect) const;
  50.     operator FW_SPlatformRect() const;
  51.     
  52.     // ----- Modification -----
  53.     void    Clear();
  54.     void    Set(XMPCoordinate left, XMPCoordinate top, XMPCoordinate right, XMPCoordinate bottom);
  55.     void    Set(const FW_CPoint& topLeft, XMPCoordinate width, XMPCoordinate height);
  56.     void    SetInt(short left, short top, short right, short bottom);
  57.     void    Offset(XMPCoordinate x, XMPCoordinate y);
  58.     void    Offset(const FW_CPoint& offset);
  59.     void    Place(XMPCoordinate x, XMPCoordinate y);
  60.     void    Place(const FW_CPoint& offset);
  61.     void    Inset(XMPCoordinate x, XMPCoordinate y);
  62.     void    Map(const FW_CRect& srcRect, const FW_CRect& dstRect);
  63.     
  64.     void    operator&=(const FW_CRect& rect);                // Intersect with rectangle
  65.     void    operator|=(const FW_CRect& rect);                // Union with rectangle
  66.     void    operator|=(const FW_CPoint& point);            // Expand to fit point
  67.     
  68.     void    Sort();
  69.         
  70.     // ----- Accessors -----
  71.     
  72.     const FW_CPoint&     TopLeft() const
  73.                                 {return *(FW_CPoint*)&left;}
  74.     FW_CPoint&            TopLeft()
  75.                                 {return *(FW_CPoint*)&left;}
  76.     const FW_CPoint&     BotRight() const
  77.                                 {return *(FW_CPoint*)&right;}
  78.     FW_CPoint&            BotRight()
  79.                                 {return *(FW_CPoint*)&right;}
  80.     XMPCoordinate        Width() const
  81.                                 {return right-left;}
  82.     XMPCoordinate        Height() const
  83.                                 {return bottom-top;}
  84.     
  85.     FW_CPoint& operator[](FW_PointSelector sel);        
  86.     const FW_CPoint& operator[](FW_PointSelector sel) const;
  87.     
  88.     // ----- Testing -----
  89.     FW_Boolean    operator==( const FW_CRect& ) const;
  90.     FW_Boolean    operator!=( const FW_CRect &r ) const
  91.                             {return !(*this==r);}
  92.     
  93.     FW_Boolean     IsEmpty() const;
  94.     FW_Boolean     Contains(const FW_CPoint& point) const;
  95.     FW_Boolean     Contains(const FW_CRect& rect) const;
  96.     FW_Boolean     IsIntersecting(const FW_CRect& rect) const;
  97.     FW_CRect     Intersects(const FW_CRect& rect) const;
  98.  
  99.  
  100.     // ----- Stream -----
  101.     void            Flatten(FW_CWritableStream& stream);
  102.     void            Unflatten(FW_CReadableStream& stream);
  103. };
  104.  
  105.  
  106. #endif
  107.